package service

import (
	"example.com/m/v2/model/mysql"
	"example.com/m/v2/types"
	"gorm.io/gorm"
)

type Fonts struct {
	BaseService
	db *gorm.DB
}

func NewFonts(svcCtx *ServiceContext, db *gorm.DB) *Fonts {
	res := Fonts{db: db, BaseService: BaseService{svcCtx: svcCtx}}
	return &res
}

func (l *Fonts) GetListByPage(req *types.DesignFontsReq) (*[]mysql.Fonts, int64) {
	var res *[]mysql.Fonts
	var total int64
	query := l.db

	page := 1
	if req.Page != 0 {
		page = req.Page
	}

	pageSize := 20
	if req.PageSize != 0 {
		pageSize = req.PageSize
	}
	query.Count(&total)
	query.Offset(pageSize * (page - 1)).Limit(pageSize).Find(&res)
	return res, total
}
